var config = require("core/config");
var host = config.host;

var delivery = host + "/delivery";

var orderUrl = delivery + "/order";
var logisticsUrl = delivery + "/sys/dict";
var paramUrl = delivery + "/sys/param";

var imgMax = 3;

module.exports.url = {
	order : {
		add : orderUrl + "/add"
	},
	logistics : {
		getLogistics : logisticsUrl + "/getLogistics"
	},
	param : {
		getDefaultValue : paramUrl + "/getDefaultValue"
	}
};

/**
 * ';'分隔图片字符串,转变成[{source:imgs[j],imgCount:""}]格式
 * 
 * @isShowAll:是否显示图片总数量，imgCount:共x张
 * @imgStr:img';'分隔图片字符串
 * @callback:回调函数
 */
var imgFormatFun = function(isShowAll, imgStr) {
	var imgs = imgStr.split(";");
	if (imgs.length > 0) {
		// 图片的数据
		var jsonImgs = [];
		var imgsL = imgs.length;
		if (imgsL >imgMax&&isShowAll) {
			imgsL = imgMax;
		}
		// 图片的数据
		for (var j = 0; j < imgsL; j++) {
			if (j == (imgsL - 1)&&isShowAll) {
				jsonImgs.push({
					source : imgs[j],
					imgCount : "共" + imgs.length + "张"
				});
			} else {
				jsonImgs.push({
					source : imgs[j],
					imgCount : ""
				});
			}
		}
		return jsonImgs;
	}
}
module.exports.fun = {
		img : {
			format : imgFormatFun
		}
};
